package org.clipjoint.controller;

import org.clipjoint.entity.Game;
import org.clipjoint.service.GameService;
import org.clipjoint.service.impl.GameServiceImpl;
import org.clipjoint.vo.JsonResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/BanGame")
public class BanGameController extends HttpServlet {

    private static final long serialVersionUID = 6L;

    private GameService gameService =  new GameServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        String method = request.getParameter("method");

        switch (method) {
            case "BanGame":
                BanGame(request, response);
                break;
            default:
                break;
        }
    }

    private void BanGame(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        // 调用service修改用户信息
        List<Game> BanGAMEList = null;
        try {
            BanGAMEList = gameService.BanGAME();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        request.getSession().setAttribute("BanGAMEList",BanGAMEList);
        response.getWriter().print(JsonResult.builder().data(BanGAMEList).code(0).build().toJsonString());

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
